package jax.lang;
class JClass extends JObject {
	var minor_version:Int;
	var major_version:Int;
	var const_pool_count:Int;
	var const_pool:Array<JConstant>;
	var access_flags:Int;
	var bitmask:Int;
	var this_id:Int;
	var super_id:Int;
	var interf_count:Int;
	var interfaces:Array<Int>;
	var cfields:Array<JClassField>;
	var methods:Array<JMethod>;
	function new() {
		super();
		_type = "java/lang/Class";
	}
	function getInterfaces():Array<String> {
		var r = [];
		for(i in interfaces) {
			r.push(Std.string(const_pool[i]));
		}
		return r;
	}
	function getName():String {
		return JVM.stringConst(const_pool[JVM.resolveRef(const_pool[this_id])]);
	}
	function getSuper():String {
		return JVM.stringConst(const_pool[JVM.resolveRef(const_pool[super_id])]);
	}
	function getMethod(nt:JConstant, pool) {
		switch(nt) {
			case nameandtype(n, t):
				for(me in methods) {
					if(JVM.toNativeValue(JVM.toValue(pool[n])) == JVM.toNativeValue(JVM.toValue(pool[me.name_index]))) {
						//trace(me);
						return me;
					}
				}
				return null;
			default: return null;
		}
	}
	override function toString() {
		return "Java Class: "+getName();
	}
	function initc() {
		#if debug
			trace("Initiating "+toString());
		for(f in cfields) {
			switch(const_pool[f.descriptor_index]) {
				case nameandtype(n, t):
					trace("FIELD:"+const_pool[n]+": "+const_pool[t]);
				default:
					trace("FIELD: "+const_pool[f.descriptor_index]);
			}
		}
		#end
	}
}